<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	template="/WEB-INF/layouts/standard.xhtml" 
	xmlns:h="http://java.sun.com/jsf/html" 
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:fn="http://www.bss.com/functions">
	
	<f:metadata>
        <f:viewParam name="forCurrent" id="forCurrent" />
    </f:metadata>
	
	<ui:define name="headIncludes">
		<style>
			.ui-datagrid-content {
				border:0px;
			}
		</style>
	</ui:define>
	

	<ui:define name="formheader">
		<h2>Room Allocation</h2>
	</ui:define>

	<ui:define name="content">

		<h:messages />
		<h:form id="roomOccForm" prependId="false">

		<h:commandButton value="Continue Check-in" action="#{roomOccupancyController.continueAdmission}" />

		
		<h:inputHidden id="selectedPatientId" value="#{roomOccupancyController.selectedPatientId}" />
		<h:inputHidden id="selectedRoomId" value="#{roomOccupancyController.roomBooking.room.id}" />
		<h:inputHidden id="selectedBedId" value="#{roomOccupancyController.bedBooking.bed.id}" />
			
		<p:outputLabel value="#{forCurrent}"/>
			
			
		
			<h2>ROOMS</h2>
			<hr />
			<ui:repeat var="building" value="#{roomOccupancyController.buildings}" >
			<h3>Building #{building.name}</h3>
			<hr/>
			<ui:repeat var="floor" value="#{arrayCreator[building.floors]}" >				
				<h4>Floor #{floor}</h4>													
					<p:dataGrid value="#{fn:call(roomOccupancyController,'findRooms',fn:concat(fn:concat(fn:concat(fn:concat('building.id=',building.id),',floor='),floor),',dormitory=false'))}" 
						var="room" columns="7">
						<p:column>
							<p:panel id="roomPanel" style="background-color: #{room.occupied ? 'gray':'green'}; width:90px; height: 30px">
								<p:selectBooleanCheckbox rendered="#{not room.occupied}"  value="#{room.selected}" 
									itemLabel="#{room.roomNumber}" style="color:white;"/>								
								<h:outputLabel rendered="#{room.occupied}"  value="#{room.roomNumber}" onclick="PF('allocatePatient').show()"/>										
							</p:panel>
							<p:overlayPanel for="roomPanel" rendered="#{room.occupied}">
								<p:outputLabel value="#{room.currentBooking.admission.patient.name }"/>
							</p:overlayPanel>
						</p:column>										
					</p:dataGrid>				
				</ui:repeat>
			</ui:repeat>	
		
			
		<h2>DORMITORIES</h2>
		<hr />		
		<ui:repeat var="building" value="#{roomOccupancyController.buildings}" >
			<h3>Building #{building.name}</h3>
			<hr/>
			<ui:repeat var="floor" value="#{arrayCreator[building.floors]}" >				
				<h4>Floor #{floor}</h4>	
					<ui:repeat var="dormitory" value="#{fn:call(roomOccupancyController,'findRooms',fn:concat(fn:concat(fn:concat(fn:concat('building.id=',building.id),',floor='),floor),',dormitory=true'))}" >
						<p:dataGrid value="#{fn:asList(dormitory.beds)}" var="bed" columns="7">
							<p:column style="background-color: #{bed.occupied ? 'gray':'green'}; ">
								<p:panel id="bedPanel" style="background-color: #{bed.occupied ? 'gray':'green'}; width:90px; height: 30px">
									<p:selectBooleanCheckbox rendered="#{not bed.occupied}" value="#{bed.selected}" itemLabel="#{bed.bedNumber}" style="color:white;"/>
									<h:outputLabel rendered="#{bed.occupied}"  value="#{bed.bedNumber}"/>
								</p:panel>
								<p:overlayPanel for="bedPanel" rendered="#{bed.occupied}">
									<p:outputLabel value="#{bed.currentBooking.admission.patient.name }"/>
								</p:overlayPanel>
							</p:column>										
						</p:dataGrid>							
					</ui:repeat>
			</ui:repeat>
		</ui:repeat>	
		
		</h:form>
		
		<p:dialog dynamic="true" widgetVar="allocatePatient">
			

			<p:commandButton value="Hide" type="button" onclick="PF('allocatePatient').hide()" />
		</p:dialog>
 
		
	</ui:define>
</ui:composition>